<template>
  <div>
    <div>
      ngnix的程序
      <span>state：</span>
    </div>
    <div style="border-bottom: 1px solid #ddd; margin-bottom: 10px; padding-bottom: 10px">
      <div>配置文件编辑</div>
      <pre style="padding: 5px">
        <div v-html="conf_html" :contenteditable="true"
ref="conf_html_ref"
></div>
      </pre>

      <div>
        <div><button type="" @click="triggersaveconf">保存配置文件</button></div>
      </div>
    </div>
    <div><button type="" @click="triggerstart">启动</button></div>
    <div><button type="" @click="()=>triggerRestart(0)">重启</button></div>
    <div><button type="" @click="()=>triggerRestart('test')">重启(测试环境)</button></div>
    <div><button type="" @click="()=>triggerRestart('prod')">重启(正式环境)</button></div>
  </div>
</template>
<script>
import axios from "axios";
export default {
  data() {
    return {
      conf_html: "",
      a: 111,
    };
  },
  mounted() {
    this.getconf();
  },
  methods: {
    async getconf() {
      var result = await axios.get("/api/ngnix/conf").then((res) => res.data);
      this.conf_html = result && result.data;
    },
    async triggerRestart(action) {
      axios.get(`/api/exec_ngnix/restart?action=${action}`);
    },
    async triggerstart() {
      axios.get("/api/exec_ngnix/start");
    },
    async triggersaveconf() {
      var self = this;
      debugger;
      axios.post("/api/exec_ngnix/conf_update", {
        content: $(this.$refs["conf_html_ref"]).text(),
      });
    },
  },
};
</script>
